<?php
/************************************
*   新浪相册 7.0
*   @file:lib_session.php
*   @intro:
*   @author:shaopu@
*   @date:Mon Nov 24 16:00:36 CST 2008
************************************/

class lib_session
{
    private $__session_id;
    private $__obj_store;
    
    public function lib_session($session_id , $obj_store)
    {
        $this->__session_id = $session_id;
//        session_id($session_id);
        session_start();
        /*
        $this->__obj_store  = $obj_store;
        $this->__obj_store->get($this->__session_id , $_SESSION);
        */
        return ;
    }
    
    public function __construct($session_id , $obj_store)
    {
        $this->lib_session($session_id , $obj_store);
    }
    
    public function get($key , &$value)
    {
        $value = $_SESSION[$key];
        return true;
    }
    
    public function set($key , $value)
    {
        $_SESSION[$key] = $value;
        
        return $this->__save();
    }
    
    public function delete($key)
    {
        unset($_SESSION[$key]);
        return $this->__save();
    }
    
    public function flush_all()
    {
        $_SESSION = array();
        return $this->__save();
    }
    
    public function init_token()
    {
        $token = md5(uniqid(microtime()));
        $this->set('__TOKEN' , $token);
        return $token;
    }
    public function get_token()
    {
        $this->get('__TOKEN' , $token);
        return $token;
    }
    
    public function init_validate()
    {
        $str = lib_random::common_str(5);
        $this->set('__VALI' , $str);
        return $str;
    }
    public function get_validate()
    {
        $this->get('__VALI' , $token);
        return $token;
    }
    /**
     * 检查验证码的程序，通过返回true，否则返回false
     *
     * @param string $user_input
     * @param string $session_code
     * @return boolean
     */
    public function check_validate_code($vcode)
    {
    	if ($vcode == "")
    	{
    		return false;
    	}
    	
    	$vcode_sess = strtoupper($this->get_validate());
    	$vcode = strtoupper($vcode);
    	
    	
    	
    	if ($vcode == $vcode_sess)
    	{
    		return true;
    	}
    	$number = array(
    	'0' 	=> 	'０',
    	'1' 	=>	'１',
    	'2'		=>	'２',
    	'3'		=>	'３',
    	'4'		=>	'４',
    	'5'		=>	'５',
    	'6'		=>	'６',
    	'7'		=>	'７',
    	'8'		=>	'８',
    	'9'		=>	'９',
    	);
    	$vcode = strtr($vcode , $number);
    	
    	if ($vcode == $vcode_sess)
    	{
    		return true;
    	}
    	return false;
    }

    
    private function __save()
    {
//        return $this->__obj_store->set($this->__session_id , $_SESSION , null , K_SESSION_EXPIRE);
    }
}


?>